package cn.ibizlab.odoo.core.odoo_event.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ievent_type;
import cn.ibizlab.odoo.core.odoo_event.domain.Event_type;
import cn.ibizlab.odoo.core.odoo_event.filter.Event_typeSearchContext;
import cn.ibizlab.odoo.core.odoo_event.service.IEvent_typeService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[活动类别] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Event_typeServiceImpl implements IEvent_typeService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ievent_typeClientService event_typeClientService;

    @Override
    public void updateBatch(List<Event_type> event_types, int batchSize) {

        //event_typeClientService.updateBatch(event_types,batchSize) ;

    }

    @Override
    public Event_type get(Integer id) {
        Ievent_type clientModel = event_typeClientService.createModel();
        clientModel.setId(id);
        event_typeClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Event_type get(Event_type event_type) {
        Event_type retevent_type = this.get(event_type.getId()) ;
    	BeanCopier copier=BeanCopier.create(retevent_type.getClass(), event_type.getClass(), false);
        copier.copy(retevent_type, event_type, null);
        return event_type ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ievent_type clientModel = event_typeClientService.createModel();
        clientModel.setId(id);
        event_typeClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //event_typeClientService.removeBatch(event_types) ;

    }

    @Override
    public boolean update(Event_type event_type) {
        boolean bOk = false ;
        Ievent_type clientModel = this.convert2Model(event_type,null);
        event_typeClientService.update(clientModel) ;
        this.convert2Domain(clientModel,event_type) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public boolean create(Event_type event_type) {
        boolean bOk = false ;
        Ievent_type clientModel = this.convert2Model(event_type,null);
        event_typeClientService.create(clientModel) ;
        this.convert2Domain(clientModel,event_type);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void createBatch(List<Event_type> event_types, int batchSize) {

                        //event_typeClientService.createBatch(event_types,batchSize) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Event_type> searchDefault(Event_typeSearchContext context) {
        List<Event_type> list = new ArrayList<Event_type>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_type> clientModelList = event_typeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_type clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_type>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据用户查询
     */
    @Override
    public Page<Event_type> selectByOdoo_create(Integer id){
        Event_typeSearchContext context = new Event_typeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_type> list = new ArrayList<Event_type>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_type> clientModelList = event_typeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_type clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_type>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Event_type> selectByOdoo_write(Integer id){
        Event_typeSearchContext context = new Event_typeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_type> list = new ArrayList<Event_type>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_type> clientModelList = event_typeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_type clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_type>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ievent_type convert2Model(Event_type domain , Ievent_type model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = event_typeClientService.createModel() ;
        }

         if(domain.getDefault_registration_maxDirtyFlag())
            model.setDefault_registration_max(domain.getDefault_registration_max());
         if(domain.getEvent_type_mail_idsDirtyFlag())
            model.setEvent_type_mail_ids(domain.getEvent_type_mail_ids());
         if(domain.getDefault_hashtagDirtyFlag())
            model.setDefault_hashtag(domain.getDefault_hashtag());
         if(domain.getDefault_timezoneDirtyFlag())
            model.setDefault_timezone(domain.getDefault_timezone());
         if(domain.getDefault_registration_minDirtyFlag())
            model.setDefault_registration_min(domain.getDefault_registration_min());
         if(domain.getEvent_ticket_idsDirtyFlag())
            model.setEvent_ticket_ids(domain.getEvent_ticket_ids());
         if(domain.getUse_ticketingDirtyFlag())
            model.setUse_ticketing(domain.getUse_ticketing());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getIs_onlineDirtyFlag())
            model.setIs_online(domain.getIs_online());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getAuto_confirmDirtyFlag())
            model.setAuto_confirm(domain.getAuto_confirm());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getWebsite_menuDirtyFlag())
            model.setWebsite_menu(domain.getWebsite_menu());
         if(domain.getUse_hashtagDirtyFlag())
            model.setUse_hashtag(domain.getUse_hashtag());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getHas_seats_limitationDirtyFlag())
            model.setHas_seats_limitation(domain.getHas_seats_limitation());
         if(domain.getUse_mail_scheduleDirtyFlag())
            model.setUse_mail_schedule(domain.getUse_mail_schedule());
         if(domain.getUse_timezoneDirtyFlag())
            model.setUse_timezone(domain.getUse_timezone());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
        return model ;
    }

    public Event_type convert2Domain( Ievent_type model ,Event_type domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Event_type();
        }

        if(model.getDefault_registration_maxDirtyFlag())
            domain.setDefault_registration_max(model.getDefault_registration_max());
        if(model.getEvent_type_mail_idsDirtyFlag())
            domain.setEvent_type_mail_ids(model.getEvent_type_mail_ids());
        if(model.getDefault_hashtagDirtyFlag())
            domain.setDefault_hashtag(model.getDefault_hashtag());
        if(model.getDefault_timezoneDirtyFlag())
            domain.setDefault_timezone(model.getDefault_timezone());
        if(model.getDefault_registration_minDirtyFlag())
            domain.setDefault_registration_min(model.getDefault_registration_min());
        if(model.getEvent_ticket_idsDirtyFlag())
            domain.setEvent_ticket_ids(model.getEvent_ticket_ids());
        if(model.getUse_ticketingDirtyFlag())
            domain.setUse_ticketing(model.getUse_ticketing());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getIs_onlineDirtyFlag())
            domain.setIs_online(model.getIs_online());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getAuto_confirmDirtyFlag())
            domain.setAuto_confirm(model.getAuto_confirm());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getWebsite_menuDirtyFlag())
            domain.setWebsite_menu(model.getWebsite_menu());
        if(model.getUse_hashtagDirtyFlag())
            domain.setUse_hashtag(model.getUse_hashtag());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getHas_seats_limitationDirtyFlag())
            domain.setHas_seats_limitation(model.getHas_seats_limitation());
        if(model.getUse_mail_scheduleDirtyFlag())
            domain.setUse_mail_schedule(model.getUse_mail_schedule());
        if(model.getUse_timezoneDirtyFlag())
            domain.setUse_timezone(model.getUse_timezone());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        return domain ;
    }


}
